home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 252 / Issue 252 - February 2009 - DPCS0209DVD.ISO / Toolkit / Internet / WinHTTrack / httrack-3.43.exe / {app} / src / htscore.h < prev    next >
Encoding:
C/C++ Source or Header  |  1980-01-01  |  12.4 KB  |  398 lines

  1. /* ------------------------------------------------------------ */
  2. /*
  3. HTTrack Website Copier, Offline Browser for Windows and Unix
  4. Copyright (C) Xavier Roche and other contributors
  5.  
  6. This program is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU General Public License
  8. as published by the Free Software Foundation; either version 2
  9. of the License, or any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  19.  
  20.  
  21. Important notes:
  22.  
  23. - We hereby ask people using this source NOT to use it in purpose of grabbing
  24. emails addresses, or collecting any other private information on persons.
  25. This would disgrace our work, and spoil the many hours we spent on it.
  26.  
  27.  
  28. Please visit our Website: http://www.httrack.com
  29. */
  30.  
  31.  
  32. /* ------------------------------------------------------------ */
  33. /* File: Main file .h                                           */
  34. /* Author: Xavier Roche                                         */
  35. /* ------------------------------------------------------------ */
  36.  
  37. // Fichier librairie .h
  38. #ifndef HTS_CORE_DEFH
  39. #define HTS_CORE_DEFH
  40.  
  41. #include "htsglobal.h"
  42.  
  43. /* specific definitions */
  44. #include "htsbase.h"
  45. // Includes & dΘfinitions
  46. #include <sys/types.h>
  47. #include <sys/stat.h>
  48. #ifdef _WIN32
  49. #ifndef  _WIN32_WCE
  50. #include <conio.h>
  51. #endif
  52. #ifndef  _WIN32_WCE
  53. #include <direct.h>
  54. #endif
  55. #else
  56. #ifndef _WIN32
  57. #include <unistd.h>
  58. #endif
  59. #endif
  60. /* END specific definitions */
  61.  
  62. /* Forward definitions */
  63. #ifndef HTS_DEF_FWSTRUCT_lien_url
  64. #define HTS_DEF_FWSTRUCT_lien_url
  65. typedef struct lien_url lien_url;
  66. #endif
  67. #ifndef HTS_DEF_FWSTRUCT_lien_back
  68. #define HTS_DEF_FWSTRUCT_lien_back
  69. typedef struct lien_back lien_back;
  70. #endif
  71. #ifndef HTS_DEF_FWSTRUCT_struct_back
  72. #define HTS_DEF_FWSTRUCT_struct_back
  73. typedef struct struct_back struct_back;
  74. #endif
  75. #ifndef HTS_DEF_FWSTRUCT_cache_back
  76. #define HTS_DEF_FWSTRUCT_cache_back
  77. typedef struct cache_back cache_back;
  78. #endif
  79. #ifndef HTS_DEF_FWSTRUCT_hash_struct
  80. #define HTS_DEF_FWSTRUCT_hash_struct
  81. typedef struct hash_struct hash_struct;
  82. #endif
  83. #ifndef HTS_DEF_FWSTRUCT_filecreate_params
  84. #define HTS_DEF_FWSTRUCT_filecreate_params
  85. typedef struct filecreate_params filecreate_params;
  86. #endif
  87.  
  88. // Include htslib.h for all types
  89. #include "htslib.h"
  90.  
  91. // options
  92. #include "htsopt.h"
  93.  
  94. // INCLUDES .H PARTIES DE CODE HTTRACK
  95.  
  96. // routine main
  97. #include "htscoremain.h"
  98.  
  99. // core routines
  100. #include "htscore.h"
  101.  
  102. // divers outils pour httrack.c
  103. #include "htstools.h"
  104.  
  105. // aide pour la version en ligne de commande
  106. #include "htshelp.h"
  107.  
  108. // gΘnΘration du nom de fichier α sauver
  109. #include "htsname.h"
  110.  
  111. // gestion ftp
  112. #include "htsftp.h"
  113.  
  114. // gestion interception d'URL
  115. #include "htscatchurl.h"
  116.  
  117. // gestion robots.txt
  118. #include "htsrobots.h"
  119.  
  120. // routines d'acceptation de liens
  121. #include "htswizard.h"
  122.  
  123. // routines de regexp
  124. #include "htsfilters.h"
  125.  
  126. // gestion backing
  127. #include "htsback.h"
  128.  
  129. // gestion cache
  130. #include "htscache.h"
  131.  
  132. // gestion hashage
  133. #include "htshash.h"
  134. #include "htsinthash.h"
  135.  
  136. #include "htsdefines.h"
  137.  
  138. #include "hts-indextmpl.h"
  139.  
  140. // structure d'un lien
  141. #ifndef HTS_DEF_FWSTRUCT_lien_url
  142. #define HTS_DEF_FWSTRUCT_lien_url
  143. typedef struct lien_url lien_url;
  144. #endif
  145. struct lien_url {
  146.   char firstblock;      // flag 1=premier malloc 
  147.   char link_import;     // lien importΘ α la suite d'un moved - ne pas appliquer les rΦgles classiques up/down
  148.   int depth;            // profondeur autorisΘe lien ; >0 forte 0=faible
  149.   int pass2;            // traiter aprΦs les autres, seconde passe. si == -1, lien traitΘ en background
  150.   int premier;          // pointeur sur le premier lien qui a donnΘ lieu aux autres liens du domaine
  151.   int precedent;        // pointeur sur le lien qui a donnΘ lieu α ce lien prΘcis
  152.   //int moved;          // pointeur sur moved
  153.   int retry;            // nombre de retry restants
  154.   int testmode;         // mode test uniquement, envoyer juste un head!
  155.   char* adr;            // adresse
  156.   char* fil;            // nom du fichier distant
  157.   char* sav;            // nom α sauver sur disque (avec chemin Θventuel)
  158.   char* cod;            // chemin codebase Θventuel si classe java
  159.   char* former_adr;     // adresse initiale (avant Θventuel moved), peut Ωtre nulle
  160.   char* former_fil;     // nom du fichier distant initial (avant Θventuel moved), peut Ωtre nul
  161.   // pour optimisation:
  162.   int hash_next[3];     // prochain lien avec mΩme valeur hash
  163. };
  164.  
  165. // chargement de fichiers en 'arriΦre plan'
  166. #ifndef HTS_DEF_FWSTRUCT_lien_back
  167. #define HTS_DEF_FWSTRUCT_lien_back
  168. typedef struct lien_back lien_back;
  169. #endif
  170. struct lien_back {
  171. #if DEBUG_CHECKINT
  172.   char magic;
  173. #endif
  174.   char url_adr[HTS_URLMAXSIZE*2];     // adresse
  175.   char url_fil[HTS_URLMAXSIZE*2];     // nom du fichier distant
  176.   char url_sav[HTS_URLMAXSIZE*2];     // nom α sauver sur disque (avec chemin Θventuel)
  177.   char referer_adr[HTS_URLMAXSIZE*2]; // adresse host page referer
  178.   char referer_fil[HTS_URLMAXSIZE*2]; // fichier page referer
  179.   char location_buffer[HTS_URLMAXSIZE*2];  // "location" en cas de "moved" (302,..)
  180.   char* tmpfile;                           // nom α sauver temporairement (compressΘ)
  181.   char tmpfile_buffer[HTS_URLMAXSIZE*2];   // buffer pour le nom α sauver temporairement
  182.   char send_too[1024];    // donnΘes α envoyer en mΩme temps que le header
  183.   int status;             // status (-1=non utilisΘ, 0: prΩt, >0: opΘration en cours)
  184.   int locked;             // locked (to be used soon)
  185.   int testmode;           // mode de test
  186.   int timeout;            // gΘrer des timeouts? (!=0  : nombre de secondes)
  187.   TStamp timeout_refresh; // si oui, time refresh
  188.   int rateout;            // timeout refresh? (!=0 : taux minimum tolΘrΘ en octets/s)
  189.   TStamp rateout_time;    // si oui, date de dΘpart
  190.   LLint maxfile_nonhtml;  // taille max d'un fichier non html
  191.   LLint maxfile_html;     // idem pour un ficheir html
  192.   htsblk r;               // structure htsblk de chaque objet en background 
  193.   int is_update;          // mode update
  194.   int head_request;       // requΦte HEAD?
  195.   LLint range_req_size;   // range utilisΘ
  196.   TStamp ka_time_start;   // refresh time for KA 
  197.   //
  198.   int http11;             // L'en tΩte doit Ωtre signΘ HTTP/1.1 et non HTTP/1.0
  199.   int is_chunk;           // chunk?
  200.   char* chunk_adr;        // adresse chunk en cours de chargement
  201.   LLint chunk_size;       // taille chunk en cours de chargement
  202.   LLint chunk_blocksize;  // taille data declaree par le chunk
  203.   LLint compressed_size;  // taille compressΘs (stats uniquement)
  204.   //
  205.   //int links_index;        // to access liens[links_index]
  206.   //
  207.   char info[256];         // Θventuel status pour le ftp
  208.   int stop_ftp;           // flag stop pour ftp
  209.   int finalized;          // finalized (optim memory)
  210. #if DEBUG_CHECKINT
  211.   char magic2;
  212. #endif
  213. };
  214.  
  215. #ifndef HTS_DEF_FWSTRUCT_struct_back
  216. #define HTS_DEF_FWSTRUCT_struct_back
  217. typedef struct struct_back struct_back;
  218. #endif
  219. struct struct_back {
  220.   lien_back* lnk;
  221.   int count;
  222.   inthash ready;
  223.     LLint ready_size_bytes;
  224. };
  225.  
  226. typedef struct cache_back_zip_entry cache_back_zip_entry;
  227.  
  228. // cache
  229. #ifndef HTS_DEF_FWSTRUCT_cache_back
  230. #define HTS_DEF_FWSTRUCT_cache_back
  231. typedef struct cache_back cache_back;
  232. #endif
  233. struct cache_back {
  234.   int version;        // 0 ou 1
  235.   /* */
  236.   int type;
  237.   int ro;
  238.   FILE *dat,*ndx,*olddat;
  239.   char *use;      // liste des adr+fil
  240.   FILE *lst;      // liste des fichiers pour la "purge"
  241.   FILE *txt;      // liste des fichiers (info)
  242.   char lastmodified[256];
  243.   // HASH
  244.   inthash hashtable;
  245.   // HASH for tests (naming subsystem)
  246.   inthash cached_tests;
  247.   // fichiers log optionnels
  248.   FILE* log;
  249.   FILE* errlog;
  250.   // variables
  251.   int ptr_ant;      // pointeur pour anticiper
  252.   int ptr_last;     // pointeur pour anticiper
  253.   //
  254.   void *zipInput;
  255.   void *zipOutput;
  256.   cache_back_zip_entry* zipEntries;
  257.   int zipEntriesOffs;
  258.   int zipEntriesCapa;
  259. };
  260.  
  261. #ifndef HTS_DEF_FWSTRUCT_hash_struct
  262. #define HTS_DEF_FWSTRUCT_hash_struct
  263. typedef struct hash_struct hash_struct;
  264. #endif
  265. struct hash_struct {
  266.   lien_url** liens;                     // pointeur sur liens
  267.   int max_lien;                         // indice le plus grand rencontrΘ
  268.   int hash[3][HTS_HASH_SIZE];           // tables pour sav/adr-fil/former_adr-former_fil
  269. };
  270.  
  271. #ifndef HTS_DEF_FWSTRUCT_filecreate_params
  272. #define HTS_DEF_FWSTRUCT_filecreate_params
  273. typedef struct filecreate_params filecreate_params;
  274. #endif
  275. struct filecreate_params {
  276.   FILE* lst;
  277.   char path[HTS_URLMAXSIZE*2];
  278. };
  279.  
  280. /* Library internal definictions */
  281. #ifdef HTS_INTERNAL_BYTECODE
  282.  
  283. HTS_STATIC int cache_writable(cache_back* cache) {
  284.   return (cache != NULL && ( cache->dat != NULL || cache->zipOutput != NULL ) );
  285. }
  286.  
  287. HTS_STATIC int cache_readable(cache_back* cache) {
  288.   return (cache != NULL && ( cache->olddat != NULL || cache->zipInput != NULL ) );
  289. }
  290.  
  291. #endif
  292.  
  293. // Fonctions
  294.  
  295. // INCLUDES .H PARTIES DE CODE HTTRACK
  296.  
  297. /* Library internal definictions */
  298. #ifdef HTS_INTERNAL_BYTECODE
  299.  
  300. //
  301. #ifndef HTTRACK_DEFLIB
  302. HTSEXT_API int hts_is_parsing(httrackp *opt, int flag);
  303. HTSEXT_API int hts_is_testing(httrackp *opt);
  304. HTSEXT_API int hts_addurl(httrackp *opt, char** url);
  305. HTSEXT_API int hts_resetaddurl(httrackp *opt);
  306. HTSEXT_API int copy_htsopt(const httrackp* from,httrackp* to);
  307. HTSEXT_API char* hts_errmsg(httrackp *opt);
  308. HTSEXT_API int hts_setpause(httrackp *opt, int);
  309. //
  310. HTSEXT_API int hts_is_exiting(httrackp *opt);
  311. HTSEXT_API int hts_request_stop(httrackp* opt, int force);
  312. //
  313. HTSEXT_API int hts_cancel_file_push(httrackp *opt, const char *url);
  314. HTSEXT_API void hts_cancel_test(httrackp *opt);
  315. HTSEXT_API void hts_cancel_parsing(httrackp *opt);
  316. #endif
  317.  
  318. char* hts_cancel_file_pop(httrackp *opt);
  319.  
  320. #endif
  321.  
  322. //
  323.  
  324.  
  325. //int httpmirror(char* url,int level,httrackp opt);
  326. int httpmirror(char* url1,httrackp* opt);
  327. int filesave(httrackp* opt,const char* adr,int len,const char* s,const char* url_adr /* = NULL */,const char* url_fil /* = NULL */);
  328. char* hts_cancel_file_pop(httrackp *opt);
  329. int check_fatal_io_errno(void);
  330. int engine_stats(void);
  331. void host_ban(httrackp* opt,lien_url** liens,int ptr,int lien_tot,struct_back* sback,char* host);
  332. FILE* filecreate(filenote_strc *strct,const char* s);
  333. FILE* fileappend(filenote_strc *strct,const char* s);
  334. int filecreateempty(filenote_strc *strct, const char* filename);
  335. int filenote(filenote_strc *strct,const char* s,filecreate_params* params);
  336. void file_notify(httrackp* opt,const char* adr,const char* fil,const char* save,int create,int modify,int wasupdated);
  337. HTS_INLINE void usercommand(httrackp* opt,int exe,const char* cmd,const char* file,const char* adr,const char* fil);
  338. void usercommand_exe(const char* cmd,const char* file);
  339. int filters_init(char*** ptrfilters, int maxfilter, int filterinc);
  340. #ifndef HTTRACK_DEFLIB
  341. HTSEXT_API int structcheck(const char* path);
  342. HTSEXT_API int dir_exists(const char* path);
  343. #endif
  344. HTS_INLINE int fspc(httrackp *opt,FILE* fp,const char* type);
  345. char* next_token(char* p,int flag);
  346. //
  347. char* readfile(char* fil);
  348. char* readfile2(char* fil, LLint* size);
  349. char* readfile_or(char* fil,char* defaultdata);
  350. #if 0
  351. void check_rate(TStamp stat_timestart,int maxrate);
  352. #endif
  353.  
  354. // liens
  355. int liens_record(char* adr,char* fil,char* save,char* former_adr,char* former_fil,char* codebase);
  356.  
  357.  
  358. // backing, routines externes
  359. int back_pluggable_sockets(struct_back* sback, httrackp* opt);
  360. int back_pluggable_sockets_strict(struct_back* sback, httrackp* opt);
  361. int back_fill(struct_back* sback,httrackp* opt,cache_back* cache,lien_url** liens,int ptr,int numero_passe,int lien_tot);
  362. int backlinks_done(struct_back* sback,lien_url** liens,int lien_tot,int ptr);
  363. int back_fillmax(struct_back* sback,httrackp* opt,cache_back* cache,lien_url** liens,int ptr,int numero_passe,int lien_tot);
  364.  
  365. // cancel file
  366. #ifndef HTTRACK_DEFLIB
  367. HTSEXT_API int hts_cancel_file_push(httrackp *opt, const char *url);
  368. HTSEXT_API void hts_cancel_test(httrackp *opt);
  369. HTSEXT_API void hts_cancel_parsing(httrackp *opt);
  370. #endif
  371.  
  372. int ask_continue(httrackp *opt);
  373. int nombre_digit(int n);
  374.  
  375. // Java
  376. #if 0
  377. int hts_add_file(char* file,int file_position);
  378. #endif
  379.  
  380. // Polling
  381. #if HTS_POLL
  382. HTS_INLINE int check_flot(T_SOC s);
  383. HTS_INLINE int check_stdin(void);
  384. int read_stdin(char* s,int max);
  385. #endif
  386. HTS_INLINE int check_sockerror(T_SOC s);
  387. HTS_INLINE int check_sockdata(T_SOC s);
  388.  
  389. /* external modules */
  390. int htsAddLink(htsmoduleStruct* str, char* link);
  391.  
  392. // Void
  393. void voidf(void);
  394.  
  395. #define HTS_TOPINDEX "TOP_INDEX_HTTRACK"
  396.  
  397. #endif
  398.